using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the Log class.
	/// </summary>
	[Serializable]
	public partial class LogCollection : ActiveList<Log,LogCollection> 
	{	   
		public LogCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Log table.
	/// </summary>
	[Serializable]
	public partial class Log : ActiveRecord<Log>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Log()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Log(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Log(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Log(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Log", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarLogID = new TableSchema.TableColumn(schema);
				colvarLogID.ColumnName = "LogID";
				colvarLogID.DataType = DbType.Int32;
				colvarLogID.MaxLength = 0;
				colvarLogID.AutoIncrement = true;
				colvarLogID.IsNullable = false;
				colvarLogID.IsPrimaryKey = true;
				colvarLogID.IsForeignKey = false;
				colvarLogID.IsReadOnly = false;
				colvarLogID.DefaultSetting = @"";
				colvarLogID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLogID);
				
				TableSchema.TableColumn colvarEventID = new TableSchema.TableColumn(schema);
				colvarEventID.ColumnName = "EventID";
				colvarEventID.DataType = DbType.Int32;
				colvarEventID.MaxLength = 0;
				colvarEventID.AutoIncrement = false;
				colvarEventID.IsNullable = true;
				colvarEventID.IsPrimaryKey = false;
				colvarEventID.IsForeignKey = false;
				colvarEventID.IsReadOnly = false;
				colvarEventID.DefaultSetting = @"";
				colvarEventID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEventID);
				
				TableSchema.TableColumn colvarPriority = new TableSchema.TableColumn(schema);
				colvarPriority.ColumnName = "Priority";
				colvarPriority.DataType = DbType.Int32;
				colvarPriority.MaxLength = 0;
				colvarPriority.AutoIncrement = false;
				colvarPriority.IsNullable = false;
				colvarPriority.IsPrimaryKey = false;
				colvarPriority.IsForeignKey = false;
				colvarPriority.IsReadOnly = false;
				colvarPriority.DefaultSetting = @"";
				colvarPriority.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPriority);
				
				TableSchema.TableColumn colvarSeverity = new TableSchema.TableColumn(schema);
				colvarSeverity.ColumnName = "Severity";
				colvarSeverity.DataType = DbType.String;
				colvarSeverity.MaxLength = 32;
				colvarSeverity.AutoIncrement = false;
				colvarSeverity.IsNullable = false;
				colvarSeverity.IsPrimaryKey = false;
				colvarSeverity.IsForeignKey = false;
				colvarSeverity.IsReadOnly = false;
				colvarSeverity.DefaultSetting = @"";
				colvarSeverity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSeverity);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 256;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = false;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarTimestamp = new TableSchema.TableColumn(schema);
				colvarTimestamp.ColumnName = "Timestamp";
				colvarTimestamp.DataType = DbType.DateTime;
				colvarTimestamp.MaxLength = 0;
				colvarTimestamp.AutoIncrement = false;
				colvarTimestamp.IsNullable = false;
				colvarTimestamp.IsPrimaryKey = false;
				colvarTimestamp.IsForeignKey = false;
				colvarTimestamp.IsReadOnly = false;
				colvarTimestamp.DefaultSetting = @"";
				colvarTimestamp.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTimestamp);
				
				TableSchema.TableColumn colvarMachineName = new TableSchema.TableColumn(schema);
				colvarMachineName.ColumnName = "MachineName";
				colvarMachineName.DataType = DbType.String;
				colvarMachineName.MaxLength = 32;
				colvarMachineName.AutoIncrement = false;
				colvarMachineName.IsNullable = false;
				colvarMachineName.IsPrimaryKey = false;
				colvarMachineName.IsForeignKey = false;
				colvarMachineName.IsReadOnly = false;
				colvarMachineName.DefaultSetting = @"";
				colvarMachineName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMachineName);
				
				TableSchema.TableColumn colvarAppDomainName = new TableSchema.TableColumn(schema);
				colvarAppDomainName.ColumnName = "AppDomainName";
				colvarAppDomainName.DataType = DbType.String;
				colvarAppDomainName.MaxLength = 512;
				colvarAppDomainName.AutoIncrement = false;
				colvarAppDomainName.IsNullable = false;
				colvarAppDomainName.IsPrimaryKey = false;
				colvarAppDomainName.IsForeignKey = false;
				colvarAppDomainName.IsReadOnly = false;
				colvarAppDomainName.DefaultSetting = @"";
				colvarAppDomainName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAppDomainName);
				
				TableSchema.TableColumn colvarProcessID = new TableSchema.TableColumn(schema);
				colvarProcessID.ColumnName = "ProcessID";
				colvarProcessID.DataType = DbType.String;
				colvarProcessID.MaxLength = 256;
				colvarProcessID.AutoIncrement = false;
				colvarProcessID.IsNullable = false;
				colvarProcessID.IsPrimaryKey = false;
				colvarProcessID.IsForeignKey = false;
				colvarProcessID.IsReadOnly = false;
				colvarProcessID.DefaultSetting = @"";
				colvarProcessID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProcessID);
				
				TableSchema.TableColumn colvarProcessName = new TableSchema.TableColumn(schema);
				colvarProcessName.ColumnName = "ProcessName";
				colvarProcessName.DataType = DbType.String;
				colvarProcessName.MaxLength = 512;
				colvarProcessName.AutoIncrement = false;
				colvarProcessName.IsNullable = false;
				colvarProcessName.IsPrimaryKey = false;
				colvarProcessName.IsForeignKey = false;
				colvarProcessName.IsReadOnly = false;
				colvarProcessName.DefaultSetting = @"";
				colvarProcessName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarProcessName);
				
				TableSchema.TableColumn colvarThreadName = new TableSchema.TableColumn(schema);
				colvarThreadName.ColumnName = "ThreadName";
				colvarThreadName.DataType = DbType.String;
				colvarThreadName.MaxLength = 512;
				colvarThreadName.AutoIncrement = false;
				colvarThreadName.IsNullable = true;
				colvarThreadName.IsPrimaryKey = false;
				colvarThreadName.IsForeignKey = false;
				colvarThreadName.IsReadOnly = false;
				colvarThreadName.DefaultSetting = @"";
				colvarThreadName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarThreadName);
				
				TableSchema.TableColumn colvarWin32ThreadId = new TableSchema.TableColumn(schema);
				colvarWin32ThreadId.ColumnName = "Win32ThreadId";
				colvarWin32ThreadId.DataType = DbType.String;
				colvarWin32ThreadId.MaxLength = 128;
				colvarWin32ThreadId.AutoIncrement = false;
				colvarWin32ThreadId.IsNullable = true;
				colvarWin32ThreadId.IsPrimaryKey = false;
				colvarWin32ThreadId.IsForeignKey = false;
				colvarWin32ThreadId.IsReadOnly = false;
				colvarWin32ThreadId.DefaultSetting = @"";
				colvarWin32ThreadId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarWin32ThreadId);
				
				TableSchema.TableColumn colvarMessage = new TableSchema.TableColumn(schema);
				colvarMessage.ColumnName = "Message";
				colvarMessage.DataType = DbType.String;
				colvarMessage.MaxLength = 1500;
				colvarMessage.AutoIncrement = false;
				colvarMessage.IsNullable = true;
				colvarMessage.IsPrimaryKey = false;
				colvarMessage.IsForeignKey = false;
				colvarMessage.IsReadOnly = false;
				colvarMessage.DefaultSetting = @"";
				colvarMessage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMessage);
				
				TableSchema.TableColumn colvarFormattedMessage = new TableSchema.TableColumn(schema);
				colvarFormattedMessage.ColumnName = "FormattedMessage";
				colvarFormattedMessage.DataType = DbType.String;
				colvarFormattedMessage.MaxLength = 1073741823;
				colvarFormattedMessage.AutoIncrement = false;
				colvarFormattedMessage.IsNullable = true;
				colvarFormattedMessage.IsPrimaryKey = false;
				colvarFormattedMessage.IsForeignKey = false;
				colvarFormattedMessage.IsReadOnly = false;
				colvarFormattedMessage.DefaultSetting = @"";
				colvarFormattedMessage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFormattedMessage);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("Log",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("LogID")]
		public int LogID 
		{
			get { return GetColumnValue<int>(Columns.LogID); }

			set { SetColumnValue(Columns.LogID, value); }

		}

		
		
		//private int? propEventID;
		[XmlAttribute("EventID")]
		public int EventID 
		{
			get
			{
			int? propEventID = GetColumnValue<int?>(Columns.EventID);
				if (!propEventID.HasValue)
					return 0;
				return propEventID.Value;
			}

		   set { SetColumnValue(Columns.EventID, value); }

		}

		
		[XmlIgnore]
		public bool EventIDHasValue
		{
			get { return GetColumnValue<int?>("EventID") != null; }

			set
			{
				int? propEventID = GetColumnValue<int?>(Columns.EventID);
				if (!value)
					SetColumnValue(Columns.EventID, null);
				else if (value && !propEventID.HasValue)
					SetColumnValue(Columns.EventID, 0);
		   }

		}

		
		  
		[XmlAttribute("Priority")]
		public int Priority 
		{
			get { return GetColumnValue<int>(Columns.Priority); }

			set { SetColumnValue(Columns.Priority, value); }

		}

		  
		[XmlAttribute("Severity")]
		public string Severity 
		{
			get { return GetColumnValue<string>(Columns.Severity); }

			set { SetColumnValue(Columns.Severity, value); }

		}

		  
		[XmlAttribute("Title")]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }

			set { SetColumnValue(Columns.Title, value); }

		}

		  
		[XmlAttribute("Timestamp")]
		public DateTime Timestamp 
		{
			get { return GetColumnValue<DateTime>(Columns.Timestamp); }

			set { SetColumnValue(Columns.Timestamp, value); }

		}

		  
		[XmlAttribute("MachineName")]
		public string MachineName 
		{
			get { return GetColumnValue<string>(Columns.MachineName); }

			set { SetColumnValue(Columns.MachineName, value); }

		}

		  
		[XmlAttribute("AppDomainName")]
		public string AppDomainName 
		{
			get { return GetColumnValue<string>(Columns.AppDomainName); }

			set { SetColumnValue(Columns.AppDomainName, value); }

		}

		  
		[XmlAttribute("ProcessID")]
		public string ProcessID 
		{
			get { return GetColumnValue<string>(Columns.ProcessID); }

			set { SetColumnValue(Columns.ProcessID, value); }

		}

		  
		[XmlAttribute("ProcessName")]
		public string ProcessName 
		{
			get { return GetColumnValue<string>(Columns.ProcessName); }

			set { SetColumnValue(Columns.ProcessName, value); }

		}

		  
		[XmlAttribute("ThreadName")]
		public string ThreadName 
		{
			get { return GetColumnValue<string>(Columns.ThreadName); }

			set { SetColumnValue(Columns.ThreadName, value); }

		}

		  
		[XmlAttribute("Win32ThreadId")]
		public string Win32ThreadId 
		{
			get { return GetColumnValue<string>(Columns.Win32ThreadId); }

			set { SetColumnValue(Columns.Win32ThreadId, value); }

		}

		  
		[XmlAttribute("Message")]
		public string Message 
		{
			get { return GetColumnValue<string>(Columns.Message); }

			set { SetColumnValue(Columns.Message, value); }

		}

		  
		[XmlAttribute("FormattedMessage")]
		public string FormattedMessage 
		{
			get { return GetColumnValue<string>(Columns.FormattedMessage); }

			set { SetColumnValue(Columns.FormattedMessage, value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Commerce.Common.CategoryLogCollection CategoryLogRecords()
		{
			return new Commerce.Common.CategoryLogCollection().Where(CategoryLog.Columns.LogID, LogID).Load();
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varEventID,int varPriority,string varSeverity,string varTitle,DateTime varTimestamp,string varMachineName,string varAppDomainName,string varProcessID,string varProcessName,string varThreadName,string varWin32ThreadId,string varMessage,string varFormattedMessage)
		{
			Log item = new Log();
			
			item.EventID = varEventID;
			
			item.Priority = varPriority;
			
			item.Severity = varSeverity;
			
			item.Title = varTitle;
			
			item.Timestamp = varTimestamp;
			
			item.MachineName = varMachineName;
			
			item.AppDomainName = varAppDomainName;
			
			item.ProcessID = varProcessID;
			
			item.ProcessName = varProcessName;
			
			item.ThreadName = varThreadName;
			
			item.Win32ThreadId = varWin32ThreadId;
			
			item.Message = varMessage;
			
			item.FormattedMessage = varFormattedMessage;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varLogID,int varEventID,int varPriority,string varSeverity,string varTitle,DateTime varTimestamp,string varMachineName,string varAppDomainName,string varProcessID,string varProcessName,string varThreadName,string varWin32ThreadId,string varMessage,string varFormattedMessage)
		{
			Log item = new Log();
			
				item.LogID = varLogID;
			
				item.EventID = varEventID;
			
				item.Priority = varPriority;
			
				item.Severity = varSeverity;
			
				item.Title = varTitle;
			
				item.Timestamp = varTimestamp;
			
				item.MachineName = varMachineName;
			
				item.AppDomainName = varAppDomainName;
			
				item.ProcessID = varProcessID;
			
				item.ProcessName = varProcessName;
			
				item.ThreadName = varThreadName;
			
				item.Win32ThreadId = varWin32ThreadId;
			
				item.Message = varMessage;
			
				item.FormattedMessage = varFormattedMessage;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn LogIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn EventIDColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn PriorityColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn SeverityColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn TimestampColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn MachineNameColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn AppDomainNameColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn ProcessIDColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn ProcessNameColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn ThreadNameColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn Win32ThreadIdColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn MessageColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        public static TableSchema.TableColumn FormattedMessageColumn
        {
            get { return Schema.Columns[13]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string LogID = @"LogID";
			 public static string EventID = @"EventID";
			 public static string Priority = @"Priority";
			 public static string Severity = @"Severity";
			 public static string Title = @"Title";
			 public static string Timestamp = @"Timestamp";
			 public static string MachineName = @"MachineName";
			 public static string AppDomainName = @"AppDomainName";
			 public static string ProcessID = @"ProcessID";
			 public static string ProcessName = @"ProcessName";
			 public static string ThreadName = @"ThreadName";
			 public static string Win32ThreadId = @"Win32ThreadId";
			 public static string Message = @"Message";
			 public static string FormattedMessage = @"FormattedMessage";
						
		}

		#endregion
		
		
		
	}

}

